<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增tgmc客户产品基础信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tgmcusprolist-add">
            <h4 class="form-header h4">tgmc客户产品基础信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow1()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table1"></table>
                    </div>
                </div>
            </div>
            <br />
            <br />
            <div class="row">
                <div class="col-sm-offset-5 col-sm-10">
                    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:src="@{/js/jquery.tmpl.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "commondata/tgmcusprolist";
        // 初始化数据, 可以由后台传过来
        var data1 = [
            {
                id: "100",
                partType: "",
                partName: "",
                partCode: "",
                customerName: ""
            }
        ];

        var columns1 = [
            {
                checkbox: true
            },
            {
                field: 'index',
                align: 'center',
                title: "序号",
                width: 40,
                formatter: function (value, row, index) {
                    var columnIndex = $.common.sprintf("<input type='hidden' name='tgmcusprolistIndex' value='%s'>", $.table.serialNumber(index));
                    var columnId = $.common.sprintf("<input type='hidden' name='tgmcusprolist[%s].id' value='%s'>", index, row.id);
                    return columnIndex + $.table.serialNumber(index) + columnId;
                }
            },
            {
                field: 'partType',
                align: 'center',
                title: '产品类型',
                width: 100,
                formatter: function(value, row, index) {
                    var data = [{ index: index, type: value }];
                    return $("#partTypeTpl").tmpl(data).html();
                }
            },
            {
                field: 'partName',
                align: 'center',
                title: '产品名称',
                width: 70,
                formatter: function(value, row, index) {
                    var html = $.common.sprintf("<input class='form-control' type='text' name='tgmcusprolist[%s].partName' value='%s' required>", index, value);
                    return html;
                }
            },
            {
                field: 'partCode',
                align: 'center',
                title: '产品编码',
                width: 70,
                formatter: function(value, row, index) {
                    var html = $.common.sprintf("<input class='form-control' type='text' name='tgmcusprolist[%s].partCode' value='%s' required>", index, value);
                    return html;
                }
            },
            {
                field: 'customerName',
                align: 'center',
                title: '客户名称',
                width: 70,
                formatter: function(value, row, index) {
                    var data = [{ index: index, type: value }];
                    return $("#customerCodeTpl").tmpl(data).html();
                }
            }
        ];

        var options1 = {
            id: "bootstrap-table1",
            data: data1,
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
            columns: columns1
        };

        $(function() {
            $.table.init(options1);
        });

        $("#form-tgmcusprolist-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/add", $('#form-tgmcusprolist-add').serialize());
            }
        }

        function addRow1() {
            var count = $("#bootstrap-table1").bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                partType: "",
                partName: "",
                partCode: "",
                customerName: ""
            }
            sub.addRow(row, 'bootstrap-table1');
        }
    </script>
</body>
</html>

<!-- 产品类型 -->
<script id="partTypeTpl" type="text/x-jquery-tmpl">
    <div>
        <select class='form-control' name='tgmcusprolist[${index}].partType' th:with='type=${@dict.getType("commondata_part_type")}'>
            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
        </select>
    </div>
</script>

<!-- 客户名称 -->
<script id="customerCodeTpl" type="text/x-jquery-tmpl">
    <div>
        <select class='form-control' name='tgmcusprolist[${index}].customerName' th:with='type=${cuslist}'>
            <option th:each="dict : ${type}" th:text="${dict.customerName}" th:value="${dict.customerName}"></option>
        </select>
    </div>
</script>